package pchi.pchicamera.helpers;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.widget.ImageView;

public class DisplayImageAsync extends AsyncTask<String, Long, Bitmap>{

	String imgPath;
	ImageView view;
	float width;
	float height;
	public DisplayImageAsync(String imgPath, ImageView view, float width, float height) {
		this.imgPath = imgPath;
		this.view = view;
		this.width = width;
		this.height = height;
	}
	
	@Override
	protected Bitmap doInBackground(String... arg0) {
		Bitmap bm;
		// TODO Auto-generated method stub
		if(width == 0 || height == 0)
			bm = BitmapFactory.decodeFile(imgPath);
		else
			bm = BitmapHelpers.decodeFile(imgPath, width, height);
	
		BitmapHelpers.addBitmapToMemoryCache(
				BitmapHelpers.buildKey(imgPath, width, height), 
				bm);
		
		return bm;
	}

	@Override
	protected void onPostExecute(Bitmap result) {
		// TODO Auto-generated method stub
		super.onPostExecute(result);
		if(view != null)
			view.setImageBitmap(result);
	}

	
}
